/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tchepannou.limbe.impl;

import com.tchepannou.limbe.Context;
import com.tchepannou.limbe.Interceptor;
import com.tchepannou.limbe.Service;
import com.tchepannou.limbe.Util;
import com.tchepannou.limbe.engine.Engine;
import com.tchepannou.limbe.mail.MailContext;

import javax.mail.MessagingException;
import javax.servlet.ServletContext;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author herve
 */
public class MailContextImpl
    implements MailContext
{
    //-- Attribute
    private Context _delegate;
    private boolean _rollback;
    private Map<String, Object> _data = new HashMap<String, Object>();
    
    //-- Constructor
    public MailContextImpl (Context context)
    {
        _delegate = context;
    }
    
    
    //-- MailContext overrides
    @Override
    public void putData(String key, Object value)
    {
        _data.put(key, value);
    }

    @Override
    public Object getData(String key)
    {
        return _data.get(key);
    }

    @Override
    public String getBasePackage ()
    {
        return _delegate.getBasePackage ();
    }

    @Override
    public List<Interceptor> getInterceptors ()
    {
        return _delegate instanceof Engine
            ? ((Engine)_delegate).getActionInterceptors()
            : null;
    }

    @Override
    public <T extends Service> T findService (Class<T> type)
    {
        return _delegate.findService (type);
    }

    @Override
    public void setRollback (boolean rollback)
    {
        _rollback = rollback;
    }

    @Override
    public boolean isRollback ()
    {
        return _rollback;
    }

    @Override
    public Util createUtil ()
    {
        return _delegate.createUtil ();
    }

    @Override
    public ServletContext getServletContext ()
    {
        return _delegate.getServletContext ();
    }

    @Override
    public void deliverEmail (String action, Serializable data) throws IOException, MessagingException
    {
        _delegate.deliverEmail(action, data);
    }

}
